﻿using System.Text;
using XLua;

public class XLuaMgr : Singleton<XLuaMgr>
{
    public XLuaMgr()
    {
        luaenv = new LuaEnv();
    }

    public void Init()
    {
        luaenv.AddLoader(Load);
        luaenv.DoString("require 'ThermalLoading'");
        e = luaenv.Global.Get<FDelegatea>("reload_module");
        debug.log("XLuaMgr init");
    }

    public LuaEnv luaenv;
    private FDelegatea e;

    [CSharpCallLua]
    public delegate void FDelegatea(string b);

    public void ReloadModule(string Name)
    {
        e.Invoke(Name);
    }

    private byte[] Load(ref string filename)
    {
        var file = LuaFileMgr.Read(filename);
        //debug.log(filename, Encoding.UTF8.GetString(file));
        return file;
    }
}